package com.quanyan.place.mail;

import com.quanyan.common.mail.EmailUtils;
import org.apache.log4j.Logger;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class MasterStatInfo {
	private static Logger logger = Logger.getLogger(MasterStatInfo.class);
	public static Float getWithdrawalsApplyMoney(){
		Connection con = ConnectionManager.getConnection();
		PreparedStatement ps = null;
		ResultSet rs= null;
		Float total = 0f;
		try {
			ps = con.prepareStatement("select sum(money) AS total from tb_activity_withdrawals_apply where withdrawals_status in (0,2)");
			rs = ps.executeQuery();
		    while (rs.next()) {
				total = rs.getFloat("total");
		    }
		} catch (Exception e) {
			e.printStackTrace();
			return 0f;
		} finally{
			ConnectionManager.closeConnection(con, ps, rs);
		}
		return total;
	}

	public static Float getMasterAllMoney(){
		Connection con = ConnectionManager.getConnection();
		PreparedStatement ps = null;
		ResultSet rs= null;
		Float total = 0f;
		try {
			ps = con.prepareStatement("select sum(money) AS total from tb_activity_user_money");
			rs = ps.executeQuery();
			while (rs.next()) {
				total = rs.getFloat("total");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return 0f;
		} finally {
			ConnectionManager.closeConnection(con, ps, rs);
		}
		return total;
	}

	public static void masterStatMailSend(){
		try {
			Float withdrawalsApplyMoney = getWithdrawalsApplyMoney();
			System.out.println("达人提款申请总额：" + withdrawalsApplyMoney);
			Float masterAllMoney = getMasterAllMoney();
			System.out.println("达人钱包总额：" + masterAllMoney);
			Float difference = masterAllMoney - withdrawalsApplyMoney;
			EmailUtils.getInstance().sendTextEmails("jingxiong.chen@quncaotech.com;yuling.zeng@quncaotech.com", "达人今日未提现未付款金额", "达人今日未提现未付款金额：" + String.valueOf(difference));
			System.out.println("达人今日未提现未付款金额：" + difference);
		}
		catch (Exception e){
			e.printStackTrace();
			System.out.println("发送邮件失败");
		}

	}

	public static void main(String[] args) {
		MasterStatInfo.masterStatMailSend();
	}

}
